/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __LIBLINUX_LINUX_GFP_H__
#define __LIBLINUX_LINUX_GFP_H__

#define alloc_pages _wapper_alloc_pages
#include_next <linux/gfp.h>
#undef alloc_pages

extern struct page *__alloc_pages_internal(gfp_t gfp_mask, unsigned int order);
static inline struct page *
alloc_pages(gfp_t gfp_mask, unsigned int order)
{
	return __alloc_pages_internal(gfp_mask, order);
}

extern struct page *__alloc_pages_internal_cache(gfp_t gfp_mask, unsigned int order);
static inline struct page *
alloc_pages_cache(gfp_t gfp_mask, unsigned int order)
{
	return __alloc_pages_internal_cache(gfp_mask, order);
}


#undef alloc_pages_vma
#undef alloc_hugepage_vma

#define alloc_pages_vma(gfp_mask, order, vma, addr, node, false) \
	alloc_pages(gfp_mask, order)
#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \
	alloc_pages(gfp_mask, order)
/*
 * This API has been removed in upstream by following commit, so we just define
 * it as a wrapper of `alloc_pages()`.
 * ```
 *   commit 4949148ad433f6f11cf837978b2907092ec99f3a
 *   Author: Vladimir Davydov <vdavydov@virtuozzo.com>
 *   Date:   Tue Jul 26 15:24:24 2016 -0700
 *
 *       mm: charge/uncharge kmemcg from generic page allocator paths
 * ```
 */
#define alloc_kmem_pages(gfp_mask, order) alloc_pages(gfp_mask, order)

#endif /* __LIBLINUX_LINUX_GFP_H__ */
